package edu.sdjzu.exam.mapper.message;

import edu.sdjzu.exam.dto.message.SystemMessage;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper

public interface SystemMessageMapper {
    // 新增消息
    @Insert("INSERT INTO system_message (student_id, content, status) " +
            "VALUES (#{studentId}, #{content}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(SystemMessage message);

    // 修改消息状态（已读/未读）
    @Update("UPDATE system_message SET status = #{status} WHERE id = #{id}")
    int updateStatus(@Param("id") Long id, @Param("status") Integer status);

    // 查询已读消息
    @Select("SELECT * FROM system_message WHERE student_id = #{studentId} AND status = 1 ORDER BY create_time DESC")
    List<SystemMessage> findReadMessages(String studentId);

    // 查询未读消息
    @Select("SELECT * FROM system_message WHERE student_id = #{studentId} AND status = 0 ORDER BY create_time DESC")
    List<SystemMessage> findUnreadMessages(String studentId);
}
